package student.aistar.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import student.aistar.model.entity.Address;
import student.aistar.model.entity.Addressdetail;
import student.aistar.model.entity.User;

import java.util.List;

public interface UserMapper {
    @Insert("insert into user values(#{userId},#{userName},#{userPassword},#{sex},#{age},#{userImg},#{userEmail},#{userTelephone})")
    void InsertUser(User user);

    @Select("select * from user where user_telephone=#{userTelephone}")
    User selectUser(User user);


    /**
     * 查询用户地址
     * @param userId
     * @return
     */
    @Select("select * from address where user_id  = #{userId}")
    List<Address> selectAddressById(Integer userId);

    /**
     * 查询省份
     * @param addressId
     * @return
     */
    @Select("select * from addressdetail where add_id = #{addressId}")
    Addressdetail selectAddressDetail(Integer addressId);


    /**
     * 把选择用户地址的的数据插入到数据库
     * @param address
     * @return
     */
    @Insert("insert into address value(null, #{userId}, #{userName}, #{userPhone}, #{userAddress}, #{userZipcode})")
    void insertAddress(Address address);


    /**
     * 查询用户点击确认的地址
     * @param addressId
     * @return
     */
    @Select("select * from address where address_id = #{addressId}")
    Address selectAddressByAddressId(Integer addressId);


    @Update("update address set user_name=#{userName},user_phone=#{userPhone},user_address=#{userAddress},user_zipcode=#{userZipcode} where address_id=#{addressId}")
    void updateAddressByAddressId(Address address);
}
